import { request } from "@/utils/service"
import axios from "axios"
import { getToken } from "@/utils/cache/cookies"
import type { PlayRecordResponseData, FileRecordRequestData, FileRecordResponseData } from "./types/audio"

export function audios(data: FileRecordRequestData) {
  return request<FileRecordResponseData>({
    url: "audios",
    method: "post",
    data
  })
}

export function audio(data: FormData) {
  return request({
    url: "audio",
    method: "post",
    data
  })
}

export function play(id: string) {
  return axios.get(`/portal/play/${id}`, {
    headers: {
      Authorization: "Bearer " + getToken()
    },
    responseType: "arraybuffer"
  })
}

export function playRecords(id: string) {
  return request<PlayRecordResponseData>({
    url: `playrecord/${id}`,
    method: "get"
  })
}

export function del(id: string) {
  return request({
    url: `audio/${id}`,
    method: "delete"
  })
}
